# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_pyname=babel
_realname=babel
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.9.0
_core=36
pkgrel=1
pkgdesc="A collection of tools for internationalizing Python applications (mingw-w64)"
url="http://babel.pocoo.org/"
license=("BSD")
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytz")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-freezegun")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/python-babel/babel/archive/v${pkgver}.tar.gz"
           "core-${_core}.zip"::"https://unicode.org/Public/cldr/${_core}/core.zip")
noextract=("core-${_core}.zip")
sha256sums=('7df55ebc7a75b6c544c381e1cc07151c2429f73f4ed01107bd8998b96cc83f42'
            '07279e56c1f4266d140b907ef3ec379dce0a99542303a9628562ac5fe460ba43')

prepare() {
  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_pyname}-${pkgver}" "python-build-${CARCH}"
  cp "${srcdir}"/core-${_core}.zip "python-build-${CARCH}"/cldr/core-${_core}.0.zip
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python setup.py import_cldr
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}"
  msg "Python test for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python setup.py pytest || true
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}
